package com.jfirer.validator.context;

import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderCustomizableContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext;
import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder;
import com.jfirer.validator.path.api.ConnectionNode;

import javax.validation.ElementKind;

public class NodeContextBuilderImpl extends BaseContextInfo implements NodeContextBuilder
{
    
    public NodeContextBuilderImpl(String customMessageTemplate, ConnectionNode connectionNode, ConstraintValidatorContextImpl constraintValidatorContextImpl)
    {
        super(customMessageTemplate, connectionNode, constraintValidatorContextImpl);
    }
    
    @Override
    public NodeBuilderDefinedContext atKey(Object key)
    {
        connectionNode.setInIterable(true);
        connectionNode.setKey(key);
        return new NodeBuilderDefinedContextImpl(customMessageTemplate, connectionNode, constraintValidatorContextImpl);
    }
    
    @Override
    public NodeBuilderDefinedContext atIndex(Integer index)
    {
        connectionNode.setInIterable(true);
        connectionNode.setIndex(index);
        return new NodeBuilderDefinedContextImpl(customMessageTemplate, connectionNode, constraintValidatorContextImpl);
    }
    
    @Override
    public NodeBuilderCustomizableContext addNode(String name)
    {
        return addPropertyNode(name);
    }
    
    @Override
    public NodeBuilderCustomizableContext addPropertyNode(String name)
    {
        ConnectionNode next = connectionNode.next();
        next.setElementKind(ElementKind.PROPERTY);
        return new NodeBuilderCustomizableContextImpl(customMessageTemplate, next, constraintValidatorContextImpl);
    }
    
    @Override
    public LeafNodeBuilderCustomizableContext addBeanNode()
    {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public ConstraintValidatorContext addConstraintViolation()
    {
        return constraintValidatorContextImpl.addCustomConstraintViolation(connectionNode, customMessageTemplate);
    }
    
}
